<?php if (! defined('BASEPATH')) exit ('No direct script access allowed');

class Content extends MY_Controller{
	
	public function __construct(){
		parent::__construct();
		$this->load->model('articles_model');
		$this->load->model('articlescategory_model');
		$this->db = $this->load->database("default", TRUE);
	}
	
	public function index(){
		$id = $this->input->get('id');
		$id = $this->verify_id($id);
		$data = $this->articles_model->row('id ='.$id);
		$result['data'] = $data;
		$check = $this->checkCate($data['category']);
		$result['category_name'] = $this->getCategoryName($data['category'],$check);
		$this->load->view('content',$result);
	}
	
	//判断是否为一级栏目
	public function checkCate($id){
		$result = $this->articlescategory_model->row('classid ='.$id);
		if($result['level']==1){
			return 1;
		}else{
			return 0;
		}
	}
	
	//获取当前位置
	public function getLocation($id){
		$result = $this->articlescategory_model->row('classid ='.$id);
		return $result['category_name'];
	}
	
	public function getCategoryName($id,$check){
		if($check==0){
			$resData = $this->articlescategory_model->row('classid ='.$id);
			$result['sub_category_name'] = $this->getLocation($id);
			$result['category_name'] = $this->getLocation($resData['parentid']);
			$result['classid'] = $resData['parentid'];
		}else if($check==1){
			$result['category_name'] = $this->getLocation($id);
			$result['classid'] = $id;
		}else{
			exit('参数非法');
		}
		return $result;
	}
}
?>